package student.design_pattern.adapter_pattern;

class Voltage220V {
	/**
	 * 输出220V的电压
	 */
	public int output220V() {
		int src = 220;
		System.out.println("电压 = " + src + "伏");
		return src;
	}
}

interface IVoltage5V {
	int output5V();
}

/**
 * Adapter（适配器类）
 * @author zhaozhaohai
 *
 */
class VoltageAdapter extends Voltage220V implements IVoltage5V {

	@Override
	public int output5V() {
		// 获取到220V电压
		int srcV = output220V();
		// 转成5v
		int dstV = srcV / 44;
		return dstV;
	}

}


/**
 * Adaptee（适配者类）
 */
class Phone {
	
	/**
	 * 充电
	 * @param iVoltage5V iVoltage5V
	 */
	public void charging(IVoltage5V iVoltage5V) {
		if (iVoltage5V.output5V() == 5) {
			System.out.println("电压为5V，可以充电～～");
		} else if (iVoltage5V.output5V() > 5) {
			System.out.println("电压大于5V，不能充电～～");
		}
	}
}

public class Client {
	public static void main(String[] args) {
		System.out.println(" === 类适配器模式 ===");
		Phone phone = new Phone();
		phone.charging(new VoltageAdapter());
	}
}